package com.yazi.mxz.common.service.impl;

import javax.annotation.Resource;

import com.myframework.smhj.hibernate.dao.BasicService;
import com.myframework.smhj.hibernate.dao.Dao;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.yazi.mxz.common.db.dao.PrizeDao;
import com.yazi.mxz.common.entity.ValueFactory;
import com.yazi.mxz.common.entity.beans.Prize;
import com.yazi.mxz.common.service.PrizeService;

@Service("prizeService")
public class PrizeServiceImpl extends BasicService<Prize> implements PrizeService {
	private static Logger log = LoggerFactory.getLogger(PrizeServiceImpl.class);
	
	@Resource
	PrizeDao prizeDao;
	
	@Override
	protected Dao<Prize> getDao() {
		return prizeDao;
	}
	
	@Override
	public Prize add(Prize prize) {
		log.debug("add：{}", prize.getName());
		prize = ValueFactory.validate(prize);
		prize.setPrizeId(null);
		return prizeDao.persist(prize);
	}

	@Override
	public Prize edit(Prize prize) {
		log.debug("modify: prizeId={}", prize.getPrizeId());
		Prize oldPrize = prizeDao.get(prize.getPrizeId());
		oldPrize = ValueFactory.combine(prize, oldPrize);
		return prizeDao.merge(oldPrize);
	}

}
